import pika, sys

credentials = pika.PlainCredentials("liwenbin", "123456")
conn_params = pika.ConnectionParameters("192.168.1.110",credentials=credentials)
conn_broker = pika.BlockingConnection(conn_params)
channel = conn_broker.channel()

channel.exchange_declare(exchange="alternate-exchange", 
                         exchange_type="fanout",
                         passive=False,
                         durable=True,
                         internal=True,
                         auto_delete=False)

channel.exchange_declare(exchange="exchange0",
                         exchange_type="direct",
                         passive=False,
                         durable=True,
                         internal=False,
                         auto_delete=False,
                         arguments={"alternate-exchange":"alternate-exchange"})

channel.queue_declare(queue="alternate-queue",durable=True)
channel.queue_bind(queue="alternate-queue",exchange="alternate-exchange")

channel.queue_declare(queue="queue0",durable=True)
channel.queue_bind(queue="queue0",exchange="exchange0",routing_key="assurance")

msg_props = pika.BasicProperties()
msg_props.content_type = "text/plain"
msg_props.delivery_mode = 2

channel.confirm_delivery()
result = channel.basic_publish(body="message1",
                               exchange="exchange0",
                               properties=msg_props,
                               routing_key="assurance",
                               mandatory=True)
print "publish success ?: "+ str(result)
